package com.example.yc23.demo.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "review",resultMap = "RM_REVIEW_2")
public class Review implements Comparable<Review>{//实现一个内部比较器
    @TableId(type = IdType.AUTO)
    private Integer id;
    @TableField(value = "user_id",property = "user.id",select = false)
    private User user;//用户谁写的
    //value用于指定数据表字段名  property用于指定哪个属性对应前面的字段
    @TableField(value = "film_id",property = "film.id",select = false)//不查询整个电影信息，通过结果集映射
    private Film film;//哪部电影
    private String content;//影评内容
    private Integer state;//状态0未审核，1审核通过，2未通过
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;//评论时间
    @TableField(exist = false)
    private int thumbsupCount;

    @Override
    public int compareTo(Review o) {
        if (this.thumbsupCount>o.thumbsupCount){
            return -1;
        }else{
            if (this.thumbsupCount==o.thumbsupCount)
                return 0;
            else
                return 1;
        }

    }
}
